<?php
    
	include_once "include/constants.php";
	
	$ownerfname = $session->userinfo['firstname'];
    $ownerlname = $session->userinfo['lastname'];
    try {
        $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
         
        $stmt = $conn->prepare('select distinct id, concat(firstname, " ", lastname) as fullname from users where isreal = 1 and (firstname <> :ownerfname or lastname <> :ownerlname)');
        $stmt->execute(array("ownerfname" => $ownerfname, "ownerlname" => $ownerlname));
        
        $fullnames = array();
        $fullnameToId = array();
        while($row = $stmt->fetch()) {
            $fullnames[] = $row['fullname'];
            $fullnameToId[$row['fullname']] = $row['id'];
        }
        
        $ownerFullName = $session->userinfo['firstname'];
        $ownerFullName .= " " . $session->userinfo['lastname'];
        
        echo "<script>friendArray = " . json_encode($fullnames) . ";</script>";
        echo "<script>chosenFriends = []; chosenFriends.push('$ownerFullName')</script>";
        echo "<script>fullNameToId = " . json_encode($fullnameToId) . ";</script>";
        echo "<script>fullNameToId['$ownerFullName'] = \"" . $session->userinfo['id'] . "\"</script>";
        echo "<script>ownerId = " . $session->userinfo['id'] . "</script>";
        
        
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
?>

<div class="container margin-top-bottom">
	<div class="row">
		<div class="span3">
            <?php
                define('CURR_PAGE', 'create');
                include 'mn_sidebar.php';
            ?>
        </div>
		<div class="span9">
			<div class="page-header">
				<h1>Who? <small>Choose your movienight mates</small></h1>
			</div>
			
			<form class="well form-search">
				<input type="text" class="input-large search-query add-friend-typeahead" autocomplete="off" id="search-friend">
				<button type="submit" class="btn" id="add-friend">Add</button>
			</form>
			
			<table class="table table-striped" id="friend-table">
				<tbody>
					<tr>
						<td><?php echo $session->userinfo['firstname'] . " " . $session->userinfo['lastname'] ?></td>
						<td>(Owner)</td>
					</tr>
				</tbody>
			</table>
			
			<div class="page-header">
				<h1>When? <small>Choose the right night to movienight</small></h1>
			</div>
			<div class="input-append date datepicker" id="dp3" data-date="<?php echo date("d-m-Y"); ?>" data-date-format="dd-mm-yyyy">				
				<input class="span2 chosen-date" size="16" type="text" value="<?php echo date("d-m-Y"); ?>">
				<span class="add-on"><i class="icon-th"></i></span>
			</div>
			
			<div class="page-header">
				<h1>What? <small>And the winner is...</small></h1>
			</div>
            
            <button class="btn btn-large btn-primary chosen-button" data-loading-text="Loading..." style="margin-bottom: 10px;">Suggest to me!</button>
            
            <div class="modal hide fade" id="suggestion-modal" style="overflow: hidden;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3 id="myModalLabel">And the winner is...</h3>
                </div>
                <div class="modal-body">
                    <div class="row chosen-movie hidden" style="height: 150px;">
                        <div class="span" style="text-align: center;">
                            <img src="" alt="Poster" class="shadow chosen-image" width="100px" height="150px">
                        </div>
                        <div class="span" style="width: 560px;">
                            <h1 class="chosen-title">
                                <small></small>
                            </h1>
                            
                            <h4 style="margin-bottom: 4px;" class="chosen-genre"></h4>
                            <p class="chosen-tagline"></p>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-primary finish-button">Accept</button>
                    <button class="btn pull-left another-movie">Another one!</button>
                </div>
            </div>

		</div>
	</div>
</div>